package com.taoban.shopdata.core;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.taoban.shopdata.entity.PriceUpdatedCommitResult;
import com.taoban.shopdata.thread.PriceUpdatedTaskFetchThread;
import com.taoban.shopdata.thread.YHDProductCollectThread;

public class DataInterfaceRunner {
	public static final Log mLog = LogFactory.getLog(DataInterfaceRunner.class);

	public DataInterfaceRunner() {
		super();
		// TODO Auto-generated constructor stub
	}
private void init(){
	
}
public  static void main(String[] args){
	 final BlockingQueue<PriceUpdatedCommitResult> taskQueues=new ArrayBlockingQueue<PriceUpdatedCommitResult>(1);

	 ScheduledExecutorService scheduledExecutorService=Executors.newScheduledThreadPool(2);
	


	//定期想spider-server 获取价格更行任务
	scheduledExecutorService.scheduleAtFixedRate(new PriceUpdatedTaskFetchThread(taskQueues), 1,10, TimeUnit.SECONDS);
	//每隔4个小时更行一号店的产品价格将起全部的商品id以及对应的价格信息保存到一个Map 中
	scheduledExecutorService.scheduleAtFixedRate(new YHDProductCollectThread(), 1,60*60*4, TimeUnit.SECONDS);

	
	ThreadPoolExecutor1 threadPoolExecutor1 = new ThreadPoolExecutor1(2, 10, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(100));
	while(true){
	try {
		//每次处理一个任务就暂停五秒钟
		Thread.currentThread().sleep(1000*5);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	threadPoolExecutor1.fetchTaskAndExecute(taskQueues);

	}

}

}
